package cn.imnaer.service.rest.view.model;

import java.util.Comparator;

import com.fasterxml.jackson.annotation.JsonIgnore;

import cn.imnaer.service.persistence.model.City;
import cn.imnaer.service.persistence.model.Country;
import cn.imnaer.service.persistence.model.Scenic;
import cn.imnaer.service.persistence.model.State;
import cn.imnaer.service.persistence.model.UserScenicInfo;
import cn.imnaer.service.rpc.enums.EnumPlaceType;

public class Place  implements Comparable<Place>{
	private String type;
	private String placeId;
	private String image;
	private String title;
	private String location;
	private double score;
	private long   scenicCount;//如果是城市，要返回这个城市的景点数
	private double latitude;
	private double longitude;
	@JsonIgnore
	private  double   distance;
    public double getDistance() {
		return distance;
	}
	public void setDistance(double distance) {
		this.distance = distance;
	}
	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getPlaceId() {
		return placeId;
	}

	public void setPlaceId(String placeId) {
		this.placeId = placeId;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public double getScore() {
		return score;
	}

	public void setScore(double score) {
		this.score = score;
	}

	public long getScenicCount() {
		return scenicCount;
	}

	public void setScenicCount(long scenicCount) {
		this.scenicCount = scenicCount;
	}

	public void setAttribute(Object object) {
		if (object instanceof City) {
			City city = (City) object;
			this.setType(EnumPlaceType.CITY.getValue());
			this.setPlaceId(city.getCityCode());
//			this.setImage(city.getImage());
//			this.setLocation(city.getLocation());
//			this.setTitle(city.getCityName());
//			this.setLatitude(city.getLatitude());
//			this.setLongitude(city.getLongitude());

		}
		if (object instanceof BasicScenic) {
			Scenic scenic = (Scenic) object;
			this.setPlaceId(scenic.getScenicId());
			this.setLocation(scenic.getLocation());
			this.setTitle(scenic.getScenicName());
			this.setScore(scenic.getScore());
			this.setLatitude(scenic.getLatitude());
			this.setLongitude(scenic.getLongitude());
			this.setType(EnumPlaceType.SCENIC.getValue());
		}
		if (object instanceof Scenic) {
			Scenic scenic = (Scenic) object;
			this.setPlaceId(scenic.getScenicId());
			this.setLocation(scenic.getLocation());
			this.setTitle(scenic.getScenicName());
			this.setScore(scenic.getScore());
			this.setLatitude(scenic.getLatitude());
			this.setLongitude(scenic.getLongitude());
			this.setType(EnumPlaceType.SCENIC.getValue());
		}
		if (object instanceof State) {
			State state = (State) object;
			this.setPlaceId(state.getStateCode());
			this.setImage(state.getImage());
			this.setLocation(state.getLocation());
			this.setTitle(state.getStateName());
			this.setScore(state.getScore());
			this.setType(EnumPlaceType.STATE.getValue());
		}
		if (object instanceof Country) {
			Country country = (Country) object;
			this.setPlaceId(country.getCountryCode());
			this.setImage(country.getImage());
			this.setLocation("");
			this.setTitle(country.getTitle());
			this.setScore(country.getScore());
			this.setType(EnumPlaceType.COUNTRIE.getValue());
		}
		if (object instanceof UserScenicInfo) {
			UserScenicInfo userScenic = (UserScenicInfo) object;
			this.setPlaceId(userScenic.getUserScenicInfoId());
			this.setLocation(userScenic.getAddress());
			this.setTitle(userScenic.getScenicName());
			/**
			 *类型为自定义
			 */
			this.setType(EnumPlaceType.CUSTOM.getValue());
		}
	}
	@Override
	public String toString() {
		return "Place [type=" + type + ", placeId=" + placeId + ", image=" + image + ", title=" + title + ", location="
				+ location + ", score=" + score + ", scenicCount=" + scenicCount + ", latitude=" + latitude
				+ ", longitude=" + longitude + ", distance=" + distance + "]";
	}
	
	@Override
	public int compareTo(Place arg0) {
		double distance1 = arg0.getDistance();
		double distance2 = this.getDistance();
		if (distance1 >= distance2) {
			return -1;
		} else {
			return 1;
		}
	}

}
